import {createApp,toRaw} from 'vue'

//语言模块 未启用
// import "../src/i18n"
import {createPinia, PiniaPluginContext} from "pinia";
import router from "./router"
import ArcoVue from '@arco-design/web-vue';
// 额外引入图标库
import ArcoVueIcon from '@arco-design/web-vue/es/icon';
import '@arco-design/web-vue/dist/arco.css';

const store = createPinia()
import './style.css'
import echarts from "./utils/echarts";
import App from './App.vue';

/**=====================*/
type Options = {
    key?:string
}
const setStorage = (key:string,value:any):void => {
    localStorage.setItem(key, JSON.stringify(value))
}
const getStorage = ( key:string  )=>{
    return localStorage.getItem(key) ? JSON.parse(localStorage.getItem(key) as string) : {}
}
const piniaPlugin = (options:Options) => {
    return (context: PiniaPluginContext) => {
        const {store} = context;
        const data = getStorage( `${ options?.key ?? 'pinia'}-${store.$id}` )
        store.$subscribe(() => {
            setStorage(`${ options?.key ?? 'pinia'}-${store.$id}`, toRaw(store.$state) )
        })
        return {
            ...data
        }
    }
}
store.use(piniaPlugin({

}))
/**=====================*/


console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);
console.log(ArcoVueIcon);


const app = createApp(App);
app.provide('$echarts', echarts);
app.use(router).use(store).use(ArcoVue).use(ArcoVueIcon).mount('#app');